// pages/myclass/myclass.js
var app = getApp()
var util = require('../../utils/util.js');
var ea = require('../../utils/each.js');
Page({

  /**
   * 页面的初始数据
   */
  data: {
    getkechen: app.data.url + '/zhongxue/maoapi/getkechen',
    date: app.data.url + "/uploads/zhongxue/date.png",
    time: app.data.url + "/uploads/zhongxue/xdate.png",
    shichu: 0,
    hongdian1: true,
    jintian: {
      year: "2019",
      month: '06'
    },
    xingqi: '',
    shuzis: [
    ],
    zhous: ["日", "一", "二", "三", "四", "五", "六"],
    studentid: 0,
    kecheng: [],


    class: [
      { title: "【2019暑】四年级趣味语文入门班", src: app.data.url + "/uploads/zhongxue/kteacher.png", name: "张域名", kemu: "语文", banji: "初三二班", number: "30", date: "06月12日-12月30日", time: "周日16：00-18：30" },
      { title: "【2019暑】四年级趣味语文入门班", src: app.data.url + "/uploads/zhongxue/kteacher.png", name: "张域名", kemu: "语文", banji: "初三二班", number: "30", date: "06月12日-12月30日", time: "周日16：00-18：30" }
    ],

    zuohua: app.data.url + "/uploads/zhongxue/zuohua.png",
    youhua: app.data.url + "/uploads/zhongxue/youhuas.png",
    hongdian: app.data.url + "/uploads/zhongxue/hongdian.png",
  },

  //点击日历
  dianjiri: function (e) {
    var shichu = e.currentTarget.dataset.day;
    // console.log(shichu)
    this.setData({
      shichu: shichu,
    });
    //  this.getData();
  },
  //上一月 
  shangyiyue: function () {
    var datee = new Date();
    var year = this.data.jintian.year;
    var month = this.data.jintian.month;

    if (month == 1) {
      month = 12,
        year = year - 1;
    } else {
      console.log(month)
      month = month - 1
    }
    var shuzis = ea.strToDays(year, month);
    var xinqi = ea.timeToDays(year, month, 1)
    this.setData({
      jintian: {
        year: year,
        month: month
      },
      shuzis: shuzis,
      xingqi: xinqi
    })
    // this.getData()
  },


  //下一月
  xiayiyue: function () {
    var datee = new Date();
    var year = this.data.jintian.year;
    var month = this.data.jintian.month;

    if (month == 12) {
      month = 1,
        year = year + 1;
    } else {
      console.log(month)
      month = month + 1
    }
    var shuzis = ea.strToDays(year, month);
    var xinqi = ea.timeToDays(year, month, '01')
    this.setData({
      jintian: {
        year: year,
        month: month
      },
      shuzis: shuzis,
      xingqi: xinqi
    })
    // this.getData()
  },

  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function (options) {
    var id = options.id;
    this.setData({ studentid: id })
    var datee = new Date()
    var year = datee.getFullYear();
    var month = datee.getMonth() + 1;
    var days = datee.getDate();
    var xingqi = ea.timeToDays(year, month, '01');
    this.setData({
      jintian: {
        year: year,
        month: month
      },
      shichu: days,
      xingqi: xingqi
    })
    var newdays = ea.strToDays('2019', '06')
    this.setData({ shuzis: newdays });
    // this.getData();
  },
  // getData:function(){
  //   var jintian = this.data.jintian;
  //   var studentid = this.data.studentid;
  //   var year = jintian.year;
  //   var month = jintian.month;
  //   var day = this.data.shichu;
  //   var user = wx.getStorageSync('user');
  //   var that = this;
  //   wx.showLoading({
  //     title: '加载中',
  //   })
  //   wx.request({
  //     url: that.data.getkechen,
  //     data: { token: user.token, year: year, month: month, day: day, studentid: studentid},
  //     header: {},
  //     method: 'POST',
  //     dataType: 'json',
  //     responseType: 'text',
  //     success: function(res) {
  //       var data = res.data;
  //       console.log(data);
  //       if(data.code==200){
  //         var yue = data.data.yue;
  //         var jin = data.data.jin;
  //         var shuzis = that.data.shuzis;
  //         console.log(shuzis);
  //         var newshuzis = [];
  //         ea.each(shuzis,function(i,v){
  //           v.hongdian = false;
  //           ea.each(yue,function(is,vs){
  //             if(v.year==vs.year&&v.month==vs.month&&v.day==vs.day){
  //                 v.hongdian = true;
  //             }
  //           })
  //           newshuzis.push(v);
  //         })
  //         console.log(jin);
  //         that.setData({ shuzis: newshuzis, kecheng: jin});
  //       }else{
  //         wx.showToast({
  //           title: data.msg,
  //           icon:'none'
  //         })
  //       }
  //     },
  //     fail: function(res) {},
  //     complete: function(res) {
  //       wx.hideLoading()
  //     },
  //   })
  // },

  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady: function () {

  },

  /**
   * 生命周期函数--监听页面显示
   */
  onShow: function () {

  },

  /**
   * 生命周期函数--监听页面隐藏
   */
  onHide: function () {

  },

  /**
   * 生命周期函数--监听页面卸载
   */
  onUnload: function () {

  },

  /**
   * 页面相关事件处理函数--监听用户下拉动作
   */
  onPullDownRefresh: function () {

  },

  /**
   * 页面上拉触底事件的处理函数
   */
  onReachBottom: function () {

  },

  /**
   * 用户点击右上角分享
   */
  onShareAppMessage: function () {

  }
})